package com.yuncheng.spcyApi.busService;

import org.apache.commons.collections.CollectionUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yuncheng.spcyApi.constant.common.SpcyConstant;
import com.yuncheng.spcyApi.entity.SysConfig;
import com.yuncheng.spcyApi.service.ISysConfigService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

@Component(value = "xtParamService")
public class SysConfigParamsService {

    @Resource
    @Lazy
    private ISysConfigService sysConfigService;

    /**
     * 手动选派人员类型默认为自动选派：1开启，0不开启
     * @param fywflcode
     * @return 手动选择、自动选择
     */
    public String xpHcyByHandConfig(String fywflcode){
        String type = SpcyConstant.XPFS_SDXZ; // 手动选择

        String configParam = "sdxzhcy"+fywflcode;

        // 获取系统参数-是否开启短信验证
        List<SysConfig> config = sysConfigService.list(new LambdaQueryWrapper<SysConfig>()
                .eq(SysConfig::getConfigCode, configParam));

        if (CollectionUtils.isNotEmpty(config)){
            String configValue = config.get(0).getConfigValue();

            if(StringUtils.isNotBlank(configValue) && configValue.trim().equals("1")){
                type = SpcyConstant.XPFS_ZDXZ; // 自动选择
            }else {
                type = SpcyConstant.XPFS_SDXZ;
            }
        }

        return type;
    }

}
